/**
 * Created by chenxiang on 2017/3/15.
 */

// 加载 动画
$(document).ajaxStart(function() { Pace.restart(); });

var $Alert = {};
$Alert.info_settime_data = 0;
$Alert.info = function(data){
    if(data.id){
        var id = data.id;
    }else{
        id = '.Alert-info';
    }
    if(!data.content){
        return false;
    }
    if(!(data.time > 0)){
        data.time = 3;
    }
    if(data.url !== undefined){
        if($Alert.msg){return false;}
        $('.modal').on('hide.bs.modal',function(){
            return false;
        });
        setInterval(function(){
            var time = $('.modal b m').html();
            if((time-1)>0){
                time = time -1;
            }else{
                time = 0;
            }
            $('.modal b m').html(time);
        },1000);
        data.content = "<b>"+data.content+' <br/>稍等： <m>'+(data.time)+'</m> '+'秒后跳转</b>';
        setTimeout(function(){
            console.dir(data.url);
            window.location.href=data.url;
        },data.time * 1000);
    }
    $(id+' .modal-body').attr('data-time',data.time).html(data.content);
    data.time = data.time *1000;
    if(data.title){
        $(id+' h4.modal-title').html(data.title);
    }else{
        $(id+' h4.modal-title').html('信息');
    }
    $(id).modal('show');

    if($Alert.info_settime_data){
        clearTimeout($Alert.info_settime_data);
    }
    $Alert.info_settime_data = setTimeout(function(){
        $(id).modal('hide');
    },data.time);
}
// 弹框 js
function alert_info(content,title,time,url){
    $Alert.info({title:title,content:content,time:time,url:url});
}

// 设置 操作 店铺 js
$("#Shops").select2().change(function(){
    // alert('asdf');
    var data = {};
    var url = $(this).attr('action');
    data['id'] = $(this).val();
    data['_token'] = $('meta[name=_token]').attr('content');
    $.ajax({url:url,type:'post',data:data,success:function(data){
        if(data && data.status){
            alert_info(data.msg,'',1,'');
            // setTimeout(function(){window.location.reload()},1000)
        }else if(data.msg){
            alert_info(data.msg,'',1);
        }else{
            alert_info('修改失败','',1);
        }
    }})
})

// 点击 botton 存储 id 至 table 标签上
$('td button').click(function(){
    $(this).parents('#example1').attr('data-id',$(this).parents('tr').attr('data-id'));
});
// 自运行函数
!function(){
    var li = $('.sidebar-menu li.active');
    do{
        if(li.parents('li')[0]){
            li = li.parents('li').addClass('active');
        }
    }while(li.parents('li')[0]);
}();




